﻿package plugin.union.game
{
    import com.core.*;
    import com.core.utils.*;
    import flash.events.*;
    import manager.*;
    import morn.core.handlers.*;
    import plugin.newvip.model.*;
    import plugin.union.*;
    import uiresource.union.*;
    import view.*;
    import view.uilt.*;

    public class UnionCreateGame extends UnionCreateUI
    {
        private var _instance:UnionCreate;

        public function UnionCreateGame(param1:UnionCreate)
        {
            this._instance = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            var _loc_1:* = Control.create(UnionCreateControl, this);
            ModelProxy.addObserver("unionCreate", _loc_1);
            this.refresh();
            this.initEvent();
            return;
        }// end function

        private function initEvent() : void
        {
            btn_create.clickHandler = new Handler(this.doCreate);
            btn_close.clickHandler = new Handler(this._instance.close);
            ti_name.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            txt_getMoney.addEventListener(MouseEvent.CLICK, this.clickHandler);
            txt_getItem.addEventListener(MouseEvent.CLICK, this.clickHandler);
            txt_getvip.addEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            switch(event.currentTarget)
            {
                case txt_getMoney:
                {
                    ModelProxy.change("plugin", "open", {target:"goddess"});
                    break;
                }
                case txt_getItem:
                {
                    DialogMgr.instance.open(AppDialog.SC_BUY, {storeId:5});
                    break;
                }
                case txt_getvip:
                {
                    ModelProxy.change("plugin", "open", {target:"vip"});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function doStop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        private function doCreate() : void
        {
            var _loc_1:* = ti_name.text;
            if (!_loc_1)
            {
                WarningManager.show(5);
                return;
            }
            if (this.minggan(_loc_1))
            {
                WarningManager.show(6);
                return;
            }
            if (int(UserData.getBagData("gold")) + int(UserData.getBagData("bgold")) < 100000)
            {
                WarningManager.show(7);
                return;
            }
            if (ItemUilt.getAllCount(240202037) < 1)
            {
                WarningManager.show(8);
                return;
            }
            if (VipCheck.checkVipLevel() < 1)
            {
                WarningManager.show(150);
                return;
            }
            UnionSender._6createUnion(_loc_1);
            return;
        }// end function

        public function minggan(param1:String) : Boolean
        {
            var _loc_2:* = ModelProxy.getValue("data", "configs1.banednames");
            var _loc_3:* = _loc_2.replaceAll(param1);
            return _loc_3 != param1;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case UnionPublics.UPDATEBAG:
                {
                    this.refresh();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function refresh() : void
        {
            var _loc_1:* = UserData.getBagData("gold");
            var _loc_2:* = UserData.getBagData("bgold");
            var _loc_3:* = ItemUilt.getAllCount(240202037);
            var _loc_4:* = VipCheck.checkVipLevel();
            txt_limit.text = "上交：1、<font color=\'#" + (_loc_1 + _loc_2 >= 100000 ? ("52b335") : ("c62440")) + "\'>绑定金币*100000</font><br>      2、<font color=\'#" + (_loc_3 >= 1 ? ("52b335") : ("c62440")) + "\'>奥玛号角*1</font><br>      3、<font color=\'#" + (_loc_4 >= 1 ? ("52b335") : ("c62440")) + "\'>需要VIP等级1</font>";
            return;
        }// end function

    }
}
